/*
 * Copyright (c) 2020 hebeiyiliuba.com
 * All rights reserved.
 *
 */
package org.jeecg.modules.third.jg.report.freight.information.service;

import cn.hutool.core.util.StrUtil;
////import cn.hutool.crypto.SmUtil;
////import cn.hutool.crypto.asymmetric.SM2;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.test.JsTest;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.http.cookie.SM;
//import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.util.DateUtils;
import org.jeecg.common.util.RedisUtil;
import org.jeecg.modules.third.jg.report.freight.information.constant.CqReportConstant;
import org.jeecg.modules.third.jg.report.freight.information.constant.enums.ReportDocTypeEnum;
import org.jeecg.modules.third.jg.report.freight.information.dto.AppInfoDTO;
import org.jeecg.modules.third.jg.report.freight.information.model.R;
import org.jeecg.modules.third.jg.report.freight.information.model.Root;
import org.jeecg.modules.third.jg.report.freight.information.util.WebUtils;
import org.jeecg.modules.third.jg.report.freight.information.util.sm.SM2Util;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import zyb.cn.hutool.crypto.SmUtil;
import zyb.cn.hutool.crypto.asymmetric.KeyType;
import zyb.cn.hutool.crypto.asymmetric.SM2;
import zyb.org.bouncycastle.jce.provider.BouncyCastleProvider;
//import zyb.cn.hutool.crypto.SmUtil;
//import zyb.cn.hutool.crypto.asymmetric.KeyType;
//import zyb.cn.hutool.crypto.asymmetric.SM2;
//import zyb.

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.security.Security;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

/**
 * 重庆监管平台上报服务，交科院系统
 */
@Service
@Slf4j
public class JsuV2ReportPlatformService {

    @Resource
    private RedisUtil redisUtil;

    private String reportPlatformDomain;

    private String platformCode;

    private String publicKey;

    private String appId;

    private String appSecurity;

    private String appSenderCode;

    private String appDebugSystem;

    public AppInfoDTO getAppInfo() {
        return AppInfoDTO.builder()
                .appId(this.appId)
                .appSecurity(this.appSecurity)
                .enterpriseSenderCode(this.appSenderCode)
                .debugSystem(this.appDebugSystem)
                .build();
    }

    public void setReportInfo(String reportPlatformDomain,
                              String username,
                              String password,
                              String publickey,
                              String appId,
                              String appSecurity,
                              String appSenderCode,
                              String appDebugSystem) {
        //联调状态的App需要设置debugSystem
        if ("0".equals(appDebugSystem)) {
            appDebugSystem = "debugSystem";
        }

        this.reportPlatformDomain = reportPlatformDomain;
        this.platformCode = username;
        this.publicKey = publickey;
        this.appId = appId;
        this.appSecurity = appSecurity;
        this.appSenderCode = appSenderCode;
        this.appDebugSystem = appDebugSystem;
    }


    public String getPlatformCode() {
        return this.platformCode;
    }

    private String getLoginToken () throws Exception{
        return StrUtil.EMPTY;
    }


    /**
     * 组装交换报文
     * @param reportDocTypeEnum 上报单据类型
     * @param jsonString 报文内容
     * @return
     */
    private Root messageAssembly(ReportDocTypeEnum reportDocTypeEnum ,String jsonString)
            throws Exception {
        return null;
    }

    /**
     * 发送上报
     * {url}/方法名?timestamp={ timestamp }&encryCode={ encryCode }
     * &platformcode={ platformcode}
     * 时间戳误差需小于10分钟
     * platformcode: 平台唯一标识，联调时提供
     * encryCode: 加 签 的 编 码 ， 通 过 SM3 加 签 生 成 。 加 签 的 源 字 串 为
     * platformcode+timestamp。
     */
    public String sendReport(String requestUrl, String jsonContent)  throws Exception {
        return null;
    }
}
